package com.prince.web.controller;

import cn.hutool.json.JSONUtil;
import com.prince.aspect.AppLog;
import com.prince.entity.RequestOrder;
import com.prince.page.Page;
import com.prince.util.JsonUtil;
import com.prince.util.MapUtil;
import com.prince.web.base.BaseController;
import com.prince.web.base.SessionUtil;
import com.prince.web.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述: 销售记录
 * @Author: 王培喜 58528792@163.com
 * @Date: 2021/4/6 14:36
 */
@Controller
public class OrderController extends BaseController {

    @Autowired
    private UserOrderService userOrderService;

    /**
     * 功能描述: 分页查询订单记录
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 15:25
     */
    @AppLog
    @PostMapping("/findOrderByPage")
    public ResponseEntity<Map<String,Object>> findOrderByPage(@RequestParam Map<String,Object> params) {
        Page page = this.getRequestPageRollInfo(params);
        Map<String,Object> map = userOrderService.findOrderByPage(params,page);
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }

    /**
     * 功能描述: 添加订单
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/addOrder")
    public ResponseEntity<Map<String,Object>> addOrder(@RequestBody  String data) {
        RequestOrder params = JSONUtil.toBean(data, RequestOrder.class);
        params.setCreater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = userOrderService.addOrder(params);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 部分退款
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/returnOrder")
    public ResponseEntity<Map<String,Object>> returnOrder(Integer id) {
        Map<String,Object> map = userOrderService.returnOrder(id,SessionUtil.getSession().getLoginName());
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 全部退货
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/returnAllOrder")
    public ResponseEntity<Map<String,Object>> returnAllOrder(Integer orderId) {
        Map<String,Object> map = userOrderService.returnAllOrder(orderId,SessionUtil.getSession().getLoginName());
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
}
